<?php
//By Bing Hua
include_once 'functions.php';
include_once 'insert_functions.php';
$date = $_GET ['date'];
$cropNameWithUnit1 = $_GET ['cropNameWithUnit1'];
$cropNameWithUnit2 = $_GET ['cropNameWithUnit2'];
$cropNameWithUnit3 = $_GET ['cropNameWithUnit3'];
$cropNameWithUnit4 = $_GET ['cropNameWithUnit4'];
$cropNum1 = $_GET ['cropNum1'];
$cropNum2 = $_GET ['cropNum2'];
$cropNum3 = $_GET ['cropNum3'];
$cropNum4 = $_GET ['cropNum4'];
$cropName1 = getCropName ( $cropNameWithUnit1 );
$unit1 = getCropUnit ( $cropNameWithUnit1 );
$cropName2 = getCropName ( $cropNameWithUnit2 );
$unit2 = getCropUnit ( $cropNameWithUnit2 );
$cropName3 = getCropName ( $cropNameWithUnit3 );
$unit3 = getCropUnit ( $cropNameWithUnit3 );
$cropName4 = getCropName ( $cropNameWithUnit4 );
$unit4 = getCropUnit ( $cropNameWithUnit4 );
if ($cropNum1 != 0)
	if (! addHarvest ( getCropId ( $cropName1 ), $cropNum1, $date, getUnitId ( $unit1 ), null )) {
		updateHarvest ( getCropId ( $cropName1 ), $cropNum1, $date, getUnitId ( $unit1 ), null );
	}
if ($cropNum2 != 0)
	if (! addHarvest ( getCropId ( $cropName2 ), $cropNum2, $date, getUnitId ( $unit2 ), null )) {
		updateHarvest ( getCropId ( $cropName2 ), $cropNum2, $date, getUnitId ( $unit2 ), null );
	}
if ($cropNum3 != 0)
	if (! addHarvest ( getCropId ( $cropName3 ), $cropNum3, $date, getUnitId ( $unit3 ), null )) {
		updateHarvest ( getCropId ( $cropName3 ), $cropNum3, $date, getUnitId ( $unit3 ), null );
	}
if ($cropNum4 != 0)
	if (! addHarvest ( getCropId ( $cropName4 ), $cropNum4, $date, getUnitId ( $unit4 ), null )) {
		updateHarvest ( getCropId ( $cropName4 ), $cropNum4, $date, getUnitId ( $unit4 ), null );
	}
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=insert_harvest.php">';
?>